/* === LICENSE INFO ===
 * This source file is subject to the GPLv3 license that is bundled with this
 * package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl.txt
 * === end of LICENSE INFO === */

/*==============================================================================
  File Name   : MetaInfoUtil.cpp
  Description : This file contains implementation of MetaInfo utility functions.

  Created on  : 2010-06-22
  Updated on  : 2010-06-22
  Updated by  : Lee Shiou Ming

  Cautions    : (important notes)
  ============================================================================*/

#include "MetaInfoUtil.hpp"
#include <boost/lexical_cast.hpp>
#include <climits>

namespace gUtil
{
namespace GMetaInfo
{

void setMetaVersionMajorChange(MetaInfo& _metaInfo)
{
    if (META_VERSION_NUM_MAXVAL == _metaInfo.m_version.m_majorVerNum)
        throw MetaInfoException("Major version overflow.");

    _metaInfo.m_version.m_majorVerNum++;
    _metaInfo.m_version.m_minorVerNum = 0;
}


void setMetaVersionMinorChange(MetaInfo& _metaInfo)
{
    if (META_VERSION_NUM_MAXVAL == _metaInfo.m_version.m_minorVerNum)
        throw MetaInfoException("Minor version overflow.");

    _metaInfo.m_version.m_minorVerNum++;
}


void getMetaVersionString(const MetaInfo& _metaInfo,
        std::string& _metaVersionStr)
{
    getMetaVersionString(_metaInfo.m_version, _metaVersionStr);
}


void getMetaVersionString(const MetaVersion& _metaVersion,
        std::string& _metaVersionStr)
{
    using std::string;

    _metaVersionStr = boost::lexical_cast<string>(_metaVersion.m_majorVerNum);
    _metaVersionStr += ".";
    _metaVersionStr += boost::lexical_cast<string>(_metaVersion.m_minorVerNum);
}

}  /* end of namespace GMetaInfo */
}  /* end of namespace gUtil */
